<div class="layui-tab layui-tab-card" lay-filter="customer">
    <!--搜索框-->
    <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="layadmin-useradmin-formlist">
        <div class="layui-form-item">
            <div class="layui-inline">
                <input type="text" name="title" placeholder="标题" autocomplete="off" class="layui-input" value="">
            </div>
            <div class="layui-inline">
                <select name="is_reply">
                    <option value="">是否回复</option>
                    {foreach $alias['is_reply_alias'] as $k => $v}
                    <option value="{$k}">{$v}</option>
                    {/foreach}
                </select>
            </div>
            <div class="layui-inline">
                <button class="layui-btn layuiadmin-btn-admin layui-btn-primary" lay-submit lay-filter="LAY-user-back-search">
                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i> 搜索
                </button>
            </div>
        </div>
    </div>

    <div class="layui-card-body">
        <!--表格-->
        <table id="demo" lay-filter="test"></table>
        <!--行功能-->
        <script type="text/html" id="row_operation">
            {if check_roles('admin/question/reply')}
                {{#  if(d.is_reply == 0){ }}
                <a class="layui-btn layui-btn-normal-outline layui-btn-xs" lay-event="reply">回复</a>
                {{#  } }}
            {/if}
<!--            {if check_roles('admin/article/detail')}-->
<!--            <a class="layui-btn layui-btn-yellow-outline layui-btn-xs" lay-event="edit">详情</a>-->
<!--            {/if}-->

        </script>
        <script type="text/html" id="switchTpl">
            <input type="checkbox" name="is_common" value="{{d.id}}" lay-skin="switch" lay-text="是|否" lay-filter="isCommon" {{ d.is_common == 1 ? 'checked' : '' }}>
        </script>
    </div>
</div>

<script>
    layui.use('table',function () {
        var table = layui.table,form = layui.form;

        //初始化表格
        var tableIns = table.render({
            elem: '#demo'
            // ,height: 'full-300'
            ,url: '/admin/question/index' //数据接口
            ,page: true //开启分页
            ,limit: 15
            ,cols: [[ //表头
                {field: 'title', title: '标题',align:'center'}
                ,{field: 'content', title: '问题补充',align:'center'}
                ,{field: 'is_reply_alias', title: '是否回复',align:'center'}
                ,{field: 'doctor_name', title: '回复医生',align:'center'}
                ,{field:'is_common', title:'常见问题', templet: '#switchTpl', unresize: true}
                ,{field: 'create_time', title: '创建时间',align:'center'}
                ,{fixed: 'right', title:'操作', toolbar: '#row_operation', width:250,align:'center'}
            ]]
        });

        //监听搜索
        form.render(null, 'layadmin-useradmin-formlist');
        form.on('submit(LAY-user-back-search)', function(data){
            var field = data.field;
            tableIns.reload({
                where: field
                ,page: {
                        curr: 1 //重新从第 1 页开始
                }
            });
        });
        //监听常见操作
        form.on('switch(isCommon)', function(obj){
            // layer.tips(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis);
            $.post("{:url('question/isCommon')}",{id:this.value,is_common:obj.elem.checked},function (data) {
                layer.msg('操作成功');
                setTimeout(function () {
                    window.location.reload()
                },1000)
            })
        });


        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            console.log(obj);
            if(obj.event === 'reply'){
                var index = layer.open({
                    type: 2
                    ,title: '回复'
                    ,content: "{:url('question/reply')}?id="+data.id
                    ,shadeClose: true
                    ,shade: 0.4
                    ,area: ['400px', '500px']
                    ,btn: ['确定', '取消']
                    ,yes: function(index, layero){
                        //点击确认触发 iframe 内容中的按钮提交
                        var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
                        submit.click();
                    }
                });
            }
        });
    });
</script>
